<template>
  <a-select v-model:value="currentValue" allowClear :placeholder="props.placeholder" @change="dataChange">
    {{ currentValue }}
    <a-select-option :value="dict.dictValue" v-for="dict in dictDatas" :key="dict.dictValue">
      {{ dict.dictLabel }}
    </a-select-option>
  </a-select>
</template>
<script setup name="SelectDict">
import {tool} from 'elead-ui-tool-v3'
const props = defineProps({
  modelValue: {type: [Number, String], default: null},
  placeholder: {
    type: String,
    default: '请选择'
  },
  name: {
    type: String,
    default: ''
  }
})
const currentValue = ref(null)
const dictDatas = ref([])
const emit = defineEmits(['update:modelValue','change'])
watch(
    () => props.modelValue,
    (newValue) => {
      if (newValue) {
        currentValue.value = newValue.toString()
      } else {
        currentValue.value = null
      }
    }
)
const dataChange = () => {
  emit('update:modelValue', currentValue.value)
  emit('change', currentValue.value)
}
onMounted(async () => {
  if (props.modelValue) {
    currentValue.value = props.modelValue.toString()
  }
  dictDatas.value = await tool.dictTypeList(props.name)
})
</script>
<style></style>
